import { Decorator } from "../core/Decorator";
import { Tick } from "../core/Tick";
import { ActionStatus } from "../core/BaseNode";

export class Inverter extends Decorator {

    constructor(params?: any) {
        super(params);
        this.name = 'Inverter';
    }

    tick(tick: Tick) : ActionStatus {
        if (!this.child) {
            return ActionStatus.ERROR;
        }
        let status = this.child._execute(tick);
        if (status === ActionStatus.SUCCESS) {
            status = ActionStatus.FAILURE;
        } else if (status === ActionStatus.FAILURE) {
            status = ActionStatus.SUCCESS;
        }
        return status;
    }
}